from flask import Blueprint, request, jsonify

from app.db.crud.teacher_management_query import DepartmentQuery, department_query
from app.decorators import require_params
from app.utils.exceptions import MissingParamError, InternalServerError

department = Blueprint('department', __name__, url_prefix='/department')


@department.route('/info/get', methods=["GET"])
# @login_required
# @role_required('all_teacher')
@require_params()
def get_department_info():
    try:
        if hasattr(request, 'validated_params'):
            params: dict = request.validated_params
        else:
            raise MissingParamError("vp")
        data = department_query.get_department_info()
        return jsonify({
            "code": 200,
            "message": "success",
            "data": data
        })
    except Exception as e:
        user_facing_msg = (
            e.details.get('u-facingMsg')
            if hasattr(e, 'details') and isinstance(e.details, dict) and e.details.get('u-facingMsg', None)
            else "服务器错误"
        )
        raise InternalServerError({"u-facingMsg": user_facing_msg}) from e
